package lee.study.Data_Struct.ClassCompare;
//比较器

import java.util.PriorityQueue;

class Person {
    public int age;
    public int score;
    public String name;

    public Person(int age, int score, String name) {
        this.age = age;
        this.score = score;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", score=" + score +
                ", name='" + name + '\'' +
                '}';
    }
}

public class TestDemo3 {
    public static void main(String[] args) {
        //定义一个比较器，用于传递给priorityQueue
        AgeComparator ageComparator=new AgeComparator();

        PriorityQueue<Person> priorityQueue = new PriorityQueue<>(ageComparator);
        //这样定义，优先级队列就实现了可以根据年龄进行比较的功能

        priorityQueue.offer(new Person(16, 98, "lee"));
        priorityQueue.offer(new Person(21, 99, "shi"));

        System.out.println(priorityQueue);
    }

    public static void main1(String[] args) {
        Person person = new Person(16, 98, "lee");
        Person person1 = new Person(21, 99, "shi");

        AgeComparator cmptor = new AgeComparator();

        System.out.println(cmptor.compare(person, person1));
        //输出使用年龄比较器比较之后的结果
        ScoreComparator scoreComparator = new ScoreComparator();

        System.out.println(scoreComparator.compare(person, person1));
        //输出使用分数比较器比较之后的结果
    }
}
